﻿using System.Configuration;
using System.Xml;

namespace Higgs.Web.AtomPub.Configurations
{
    public class ConfigurationTextElement<T> : ConfigurationElement
    {
        public T Value { get; private set; }

        protected override void DeserializeElement(XmlReader reader, bool serializeCollectionKey)
        {
            Value = (T)reader.ReadElementContentAs(typeof(T), null);
        }

        protected override bool SerializeElement(XmlWriter writer, bool serializeCollectionKey)
        {
            var result = base.SerializeElement(writer, serializeCollectionKey);
            writer.WriteString(Value.ToString());

            return result;
        }

        public override string ToString()
        {
            return Value.ToString();
        }
    }
}
